#include <stdexcept>
#include <iostream>

using namespace std;
class A
{
public: 
    ~A()
    {
	cout << "A dtor" << endl;
	if (!std::uncaught_exception())
	    throw runtime_error("dtor");
	else
	    cout << "there is already an exception caught" << endl;
    }
};


int ex_src()
{
    throw runtime_error("this is a exception");
}


int ex_mid(bool toThrow)
{
    try
    {
       A a;
       if (toThrow)
           ex_src();
    }catch(exception& e)
    {
       cout << "in catch" << endl;
       //throw runtime_error(e.what()); 
       throw;
    }    
}


int main()
{
    try
    {
	ex_mid(true);
    }catch(exception& e)
    {
	cout << e.what() << endl;
    }

    return 0;
}

